package sz.szsmk.citizencard.ui.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.chenenyu.router.annotation.Route;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.SearchBean;
import sz.szsmk.citizencard.model.network.bean.response.TransBean;
import sz.szsmk.citizencard.ui.adapter.HistoryAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.util.MesageEventBus;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/16 2:22
 * description:
 */
@Route("BusTransSearchActivity")
public class BusTransSearchActivity extends IBaseActivity {

    ImageView back;
    TextView settingTitle;
    RecyclerView busSearchHistoryRv;
    private HistoryAdapter historyAdapter;
    private ArrayList<TransBean> mBean = new ArrayList<>();
    private ArrayList<String> mStringList = new ArrayList<>();

    @Override
    protected int attachLayoutRes() {
        return R.layout.bus_trans_search_activity;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {

        back = findViewById(R.id.back);
        settingTitle = findViewById(R.id.setting_title);
        busSearchHistoryRv = findViewById(R.id.bus_search_history_rv);



        settingTitle.setText("换乘搜索");
        String data = getIntent().getStringExtra("data");
        final String type = getIntent().getStringExtra("type");

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        busSearchHistoryRv.setLayoutManager(linearLayoutManager);

        historyAdapter = new HistoryAdapter(this);
        historyAdapter.GhfOnClick(new HistoryAdapter.GhfInterface() {
            @Override
            public void onClick(View view, String data,String data1,String data3,int position) {

                MesageEventBus mesageEventBus = new MesageEventBus();
                if("transstart".equals(type)){
                    mesageEventBus.setStart(mStringList.get(position));
                    mesageEventBus.setEnd("");
                }
                if("transend".equals(type)){
                    mesageEventBus.setStart("");
                    mesageEventBus.setEnd(mStringList.get(position));
                }
//                mesageEventBus.setStart(mStringList.get(position));
                mesageEventBus.setLat(mBean.get(position).getLat());
                mesageEventBus.setLog(mBean.get(position).getLog());
                EventBus.getDefault().postSticky(mesageEventBus);

                if (BusSearchHistotyActivity.instance != null) {
                    BusSearchHistotyActivity.instance.finish();
                }

                finish();
            }
        });
        busSearchHistoryRv.setAdapter(historyAdapter);

    }

    @Override
    protected void updateViews() {

    }
}
